package com.yn.common.response.driver;

import com.yn.common.constants.Constants;
import com.yn.common.enums.EnumZyOrderStatus;
import com.yn.common.enums.ZyOrderTypeEnum;
import com.yn.common.enums.ZyTransportTypeEnum;
import com.yn.common.model.zyorder.ZyOrder;
import com.yn.common.utils.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="司机端订单中心查询订单列表", description="司机端订单中心查询订单列表")
public class ZyDriverCenterListResponse extends ZyDriverOrderListResponse{

    @ApiModelProperty(value = "订单状态")
    private Integer orderStatus;

    @ApiModelProperty(value = "订单状态字符")
    private String orderStatusStr;

    public static ZyDriverCenterListResponse transfer(ZyOrder zyOrder){
        ZyDriverCenterListResponse response = new ZyDriverCenterListResponse();
        response.setOrderNo(zyOrder.getOrderNo());
        response.setId(zyOrder.getId());
        response.setStartRegionCode(zyOrder.getStartRegionCode());
        response.setEndRegionCode(zyOrder.getEndRegionCode());
        response.setStartDestination(zyOrder.getStartDestination());
        response.setEndDestination(zyOrder.getEndDestination());
        response.setStartLocality(zyOrder.getStartLocality());
        response.setEndLocality(zyOrder.getEndLocality());
        response.setRidingNumber(zyOrder.getRidingNumber());
        //订单类型
        response.setOrderType(zyOrder.getOrderType());
        response.setOrderTypeStr(ZyOrderTypeEnum.getByCode(zyOrder.getOrderType()).getName());
        //转运类型
        response.setTransportType(zyOrder.getTransportType());
        response.setTransportTypeStr(ZyTransportTypeEnum.getByCode(zyOrder.getTransportType()).getName());
        //将useCarDateTime转为LocalDateTime并格式化为年月日时分秒
        // 转换Date为LocalDateTime
       /* Date useCarDateTime = zyOrder.getUseCarDateTime();
        LocalDateTime localDateTime = useCarDateTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");*/
        response.setUserCarDateTime(DateUtil.dateToStr(zyOrder.getUseCarDateTime(), Constants.DATE_FORMAT));
        //将距离转化为KM
        Integer transferDistance = zyOrder.getTransferDistance();
        Double transferDistance2Db =(transferDistance *100.0/1000)/100;
        response.setTransferDistance(transferDistance2Db);
        //response.setOrderPayPrice(zyOrder.getOrderPayPrice());
        response.setOrderAllPrice(zyOrder.getOrderAllPrice());

        //订单状态
        response.setOrderStatus(zyOrder.getOrderStatus());
        response.setOrderStatusStr(EnumZyOrderStatus.getByCode(zyOrder.getOrderStatus()).getName());
        return response;
    }
}
